﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;

namespace Web2014112110
{
    public partial class UpdateInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "教师修改学生信息";
            string name;
            name = Session["name"].ToString();
            this.lblNowUser.Text =  name ;
            this.userName.Text = name;
            String strCn = "Server=pc.hstc.cn;database=dhd2014112110;uid=2014112110;pwd=19941225";
            SqlConnection cn = new SqlConnection(strCn); //建对象
            try
            {
                cn.Open();
                string strSql = "SELECT   Image FROM  TeaInfo  WHERE   (Account = N'" + this.userName.Text + "')";
                SqlCommand cmd = new SqlCommand(strSql, cn);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    this.Image.ImageUrl = dr["Image"].ToString();
                }
            }
            catch
            {

            }
            finally
            {
                cn.Close();
            }
        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["Theme"] == null)
            {
                Page.Theme = "ThemeFour";
            }
            else if (Session["Theme"].ToString() == "themeFive")
            {
                Page.Theme = "themeFive";
            }
            else if (Session["Theme"].ToString() == "themeTwo")
            {
                Page.Theme = "ThemeTwo";
            }
            else if (Session["Theme"].ToString() == "themeThree")
            {
                Page.Theme = "themeThree";
            }
            else if (Session["Theme"].ToString() == "themeFour")
            {
                Page.Theme = "themeFour";
            }
        }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112110;uid=2014112110;pwd=19941225";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();
                string strSql = "UPDATE  Student SET Name = N'" + this.txtName.Text + "', Age = " + this.txtAge.Text + ",Gender = N'" + this.txtGender.Text + "',Place = N'" + this.txtPlace.Text + "',CollegeName = N'" + this.DropDownList1.Text + "', Nation = N'" + this.DropDownList2.Text + "' WHERE(No = N'" + this.txtNo.Text + "')";
                SqlCommand cmd = new SqlCommand(strSql, cn);
                int iUpd = cmd.ExecuteNonQuery();
                if (iUpd < 1)
                {
                    this.lblInfo.Text = "更新失败！";
                    //Response.Write("<script>javascript:alert('更新失败');history.back();</script>");
                }
                else
                {
                    this.lblInfo.Text = "成功更新" + iUpd.ToString() + "条记录！";
                    //Response.Write("<script>javascript:alert('更新成功');history.back();</script>");
                }
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
                //Response.Write("<script>javascript:alert('更新出错');history.back();</script>");
            }
            finally
            {
                cn.Close();
            }
        }
    }
}